package com.j2ee.student.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.j2ee.student.domain.Course;
import com.j2ee.student.service.CourseService;
import com.j2ee.student.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Course)表控制层
 *
 * @author gsy
 * @since 2022-05-26 16:09:37
 */
@RestController
@RequestMapping("course")
public class CourseController {

/**
 * 服务对象
 */
    @Resource
    private CourseService courseService;

/**
     * 分页查询所有数据
     */
    @GetMapping
    public R page(@RequestParam int current,@RequestParam int size){
        Page<Course> page=new Page<>(current,size);
        return R.ok().setData(this.courseService.page(page));
    }


/**
 * 通过主键查询单条数据
 */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id){
        return R.ok().setData(this.courseService.getById(id));}

/**
 * 新增数据
 */
    @PostMapping
    public R save(@RequestBody Course course){
        return R.ok().setData(this.courseService.save(course));}

/**
 * 修改数据
 */
    @PutMapping
    public R updateById(@RequestBody Course course){
        return R.ok().setData(this.courseService.updateById(course));}

/**
 * 单条/批量删除数据
 */
    @DeleteMapping
    public R delete(@RequestParam List<Long> id){
        return R.ok().setData(this.courseService.removeByIds(id));}
}

